define([ 'angularAMD', 'bootstrap-datetimepicker', 'css!root/asset/bootstrap/datetimepicker/css/bootstrap-datetimepicker.css' ], function(
		angularAMD) {
	angularAMD.directive('datetimepicker', function() {
		return {
			restrict : 'A',
			require : [ '?ngModel' ],
			link : function(scope, element, attr, ctrls) {
				var nullText = attr.nullText, current
				var ngModelCtrl = ctrls[0]
				element.datetimepicker({
					format : 'YYYY-MM-DD HH:mm:ss',
					locale : 'zh-cn'
				});
				if (ngModelCtrl) {
					element.on('dp.change', function() {
						var d = element.data("DateTimePicker").date()
						ngModelCtrl.$setViewValue(d ? d.toDate() : undefined)
					})
					ngModelCtrl.$parsers.push(function(input) {
						if (input) {
							return element.data("DateTimePicker").date().toDate();
						} else {
							return input;
						}
					})
					current && element.data("DateTimePicker").date(new Date(current));
					ngModelCtrl.$formatters.push(function(input) {
						if (input) {
							current = input
							setTimeout(function() {
								element.data("DateTimePicker") && element.data("DateTimePicker").date(new Date(current));
							})
						}
						return nullText ? nullText : input;
					})
				}

			}
		}
	})
})